<template>
  <el-dialog title="策略管理" :visible.sync="deldialog" width="40%" :before-close="handleClose">
    <el-row>
      <el-col :span="10" :offset="2">机器编号：<span>{{ delInfo.innerCode }}</span></el-col>
      <el-col :span="10" :offset="2">策略名称：<span>{{ delInfo.policyName }}</span></el-col>
      <el-col :span="10" :offset="2">策略方案：<span>{{ delInfo.discount }}%</span></el-col>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消策略</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { vminnerPolicyAPI, cancelPolicyApi } from '@/api/vm'
export default {
  props: {
    deldialog: {
      type: Boolean,
      default: false
    },
    innerCode: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      delInfo: {}
    }
  },
  updated() {
    this.getVMPolicy()
  },
  methods: {
    async getVMPolicy() {
      const res = await vminnerPolicyAPI(this.innerCode.innerCode)
      this.delInfo = res.data
      console.log(res)
    },
    handleClose() {
      this.$emit('update:deldialog', false)
    },
    async cancel() {
      await cancelPolicyApi(this.delInfo.innerCode, this.delInfo.policyId)
      this.$message.info('取消策略成功')
      this.$emit('update:deldialog', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-col {
    padding-bottom: 20px;
}

.dialog-footer {
    display: flex;
    justify-content: center;
}
</style>
